layui.use(['form', 'jquery', 'layer'], function(){
    var form = layui.form;
    var $ = layui.jquery;
    var layer = layui.layer;

    //监听提交
    form.on('submit(save_config)', function(data){
        let loading = layer.load();
		$.ajax({
			url: "./ajax/edit_codename",
			type: "POST",
			data: JSON.stringify(data.field),
			contentType: 'application/json',
			dataType: 'json',
			success: function(result) {
				layer.close(loading);
				if (result.code == 200) {
				    layer.msg(result.msg, {
						icon: 1,
						time: 1000
					}, function() {
						window.location.reload()
					});
				} else {
					layer.msg(result.msg, {
						icon: 2,
						time: 3000
					});
				}
			},
			error: function(){
			    layer.close(loading);
			    layer.msg("服务器错误", {
					icon: 2,
					time: 1000
				});
			}
		});
        return false;
    });

    // 复制链接
    $("#copy_link").click(function(){
        var input = document.getElementById("code_url");
        input.select();
        document.execCommand("copy");
        layer.msg("链接已复制!");
    });
    form.on('select(styleName)', function(data){
        xuanzhe(data.value);
    });
});